home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / osi / isode / dosisode / DOSISODE80.ZIP / ISODE8.WRK / COMPAT / GETPASSW.C_N < prev    next >
Encoding:
Text File  |  1992-06-28  |  2.8 KB  |  135 lines

  1. /* getpassword.c - generic read-the-password-from-the-tty */
  2.  
  3. #ifndef    lint
  4. static char *rcsid = "$Header: /xtel/isode/isode/compat/RCS/getpassword.c,v 9.0 1992/06/16 12:07:00 isode Rel $";
  5. #endif
  6.  
  7. /* 
  8.  * $Header: /xtel/isode/isode/compat/RCS/getpassword.c,v 9.0 1992/06/16 12:07:00 isode Rel $
  9.  *
  10.  *
  11.  * $Log: getpassword.c,v $
  12.  * Revision 9.0  1992/06/16  12:07:00  isode
  13.  * Release 8.0
  14.  *
  15.  */
  16.  
  17. /*
  18.  *                  NOTICE
  19.  *
  20.  *    Acquisition, use, and distribution of this module and related
  21.  *    materials are subject to the restrictions of a license agreement.
  22.  *    Consult the Preface in the User's Manual for the full terms of
  23.  *    this agreement.
  24.  *
  25.  */
  26.  
  27.  
  28. /* LINTLIBRARY */
  29.  
  30. #include <signal.h>
  31. #include <stdio.h>
  32. #include "general.h"
  33. #include "manifest.h"
  34. #include "sys.file.h"
  35.  
  36. #ifdef    BSD44
  37. char   *getpass ();
  38. #endif
  39.  
  40. /*   */
  41.  
  42. /* roll our own since want to get past UNIX's limit of 8 octets... */
  43.  
  44. char *getpassword (prompt)
  45. char *prompt;
  46. {
  47. #ifndef    BSD44
  48.     register int    c;
  49.     int        flags,
  50.         isopen;
  51.     register char  *bp,
  52.            *ep;
  53. #if    !defined(SYS5) && !defined(XOS_2)
  54.     struct sgttyb   sg;
  55. #else
  56.     struct termio   sg;
  57. #endif
  58.     SFP        istat;
  59.     FILE    *fp;
  60.     static char buffer[BUFSIZ];
  61.  
  62. #ifdef SUNLINK_7_0
  63.     fp = stdin, isopen = 0;    /* will help greatly to work off a script */
  64. #else
  65.     if ((c = open ("/dev/tty", O_RDWR)) != NOTOK && (fp = fdopen (c, "r")))
  66.     setbuf (fp, NULLCP), isopen = 1;
  67.     else {
  68.     if (c != NOTOK)
  69.         (void) close (c);
  70.  
  71.     fp = stdin, isopen = 0;
  72.     }
  73. #endif
  74.  
  75.     istat = signal (SIGINT, SIG_IGN);
  76.  
  77. #if    !defined(SYS5) && !defined(XOS_2)
  78.     (void) gtty (fileno (fp), &sg);
  79.     flags = sg.sg_flags;
  80.     sg.sg_flags &= ~ECHO;
  81.     (void) stty (fileno (fp), &sg);
  82. #else
  83.     (void) ioctl (fileno (fp), TCGETA, (char *) &sg);
  84.     flags = sg.c_lflag;
  85.     sg.c_lflag &= ~ECHO;
  86.     (void) ioctl (fileno (fp), TCSETAW, (char *) &sg);
  87. #endif
  88.  
  89. #ifdef SUNLINK_7_0
  90.     (void) fprintf (stdout, "%s", prompt);
  91.     (void) fflush (stdout);
  92. #else
  93.     (void) fprintf (stderr, "%s", prompt);
  94.     (void) fflush (stderr);
  95. #endif
  96.  
  97.     for (ep = (bp = buffer) + sizeof buffer - 1; (c = get1c (fp)) != EOF;)
  98. #ifndef    apollo
  99.     if (c == '\n')
  100. #else
  101.     if (c == '\n' || c == '\r')
  102. #endif
  103.         break;
  104.     else
  105.         if (bp < ep)
  106.         *bp++ = c;
  107.     *bp = NULL;
  108.  
  109. #ifdef SUNLINK_7_0
  110.     (void) fprintf (stdout, "\n");
  111.     (void) fflush (stdout);
  112. #else
  113.     (void) fprintf (stderr, "\n");
  114.     (void) fflush (stderr);
  115. #endif
  116.  
  117. #if    !defined(SYS5) && !defined(XOS_2)
  118.     sg.sg_flags = flags;
  119.     (void) stty (fileno (fp), &sg);
  120. #else
  121.     sg.c_lflag = flags;
  122.     (void) ioctl (fileno (fp), TCSETAW, (char *) &sg);
  123. #endif
  124.  
  125.     (void) signal (SIGINT, istat);
  126.  
  127.     if (isopen)
  128.     (void) fclose (fp);
  129.  
  130.     return buffer;
  131. #else
  132.     return getpass (prompt);
  133. #endif
  134. }
  135.